package com.qxsx.midi.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.qxsx.midi.R;
import com.qxsx.midi.activity.exam.ExamChooseTimeActivity;
import com.qxsx.midi.model.Category;
import com.qxsx.midi.model.ClassVideo;
import com.qxsx.midi.model.Time;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Joney on 2015/8/31.
 */
public class ChooseTimerAdapter extends BaseAdapter {


    private Context context;

    private List<Time> lists;

    private int mChoose ;

    public ChooseTimerAdapter(Context context, List<Time> lists) {
        this.context = context;
        this.lists = lists;

    }



    @Override
    public int getCount() {
        return lists.size();
    }

    @Override
    public Object getItem(int position) {
        return lists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public void setChoose(int choose) {
        mChoose = choose;
        notifyDataSetChanged();
    }

    //动态添加数据
    public void addData(List<Time> addlist) {//刷新数据
        for (Time time : addlist) {
            lists.add(time);
        }
        notifyDataSetChanged();
    }



    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = convertView.inflate(context, R.layout.choose_timer_item, null);
            holder = new ViewHolder();
            holder.iv_check = (ImageView) convertView.findViewById(R.id.iv_check);
            holder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            holder.end_time =(TextView) convertView.findViewById(R.id.end_time);
            convertView.setTag(holder);

        } else {
            holder = (ViewHolder) convertView.getTag();

        }
        Time time = lists.get(position);

        holder.tv_name.setText(time.getExam_time());
        holder.end_time.setText(time.getExam_end_time());
        if (position == mChoose) {
            holder.iv_check.setVisibility(View.VISIBLE);
        }else{
            holder.iv_check.setVisibility(View.GONE);
        }

        return convertView;
    }


    private class ViewHolder {
        ImageView iv_check;
        TextView tv_name;
        TextView end_time;
    }
}

